import axios from 'axios'
import { Message } from 'element-ui'

export async function upload(formData) {
  const res = await axios({
    url: process.env.VUE_APP_BASE_API + '/admin/admin/uploadphoto',
    method: 'POST',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
      // 'Authorization': LocalStorageUtil.getCookie(LocalStorageUtil.STORAGES_TOKEN)
    }
  }).catch(function(error) {
    Message({
      message: error.message,
      type: 'error',
      duration: 5 * 1000
    })
    Promise.reject(error)
  })
  return res.data
}

/**
 * 获取默认配置信息
 */
/*export async function getDefault() {
  const res = await axios({
    url: process.env.VUE_APP_SETTING_API + '/api/tools/env',
    method: 'GET'
  }).catch(function(error) {
    Message({
      message: error.message,
      type: 'error',
      duration: 5 * 1000
    })
    Promise.reject(error)
  })
  return res.data
}*/

/**
 * 格式化文件为formData对象
 * @param {*} file 文件对象
 */
export function formatFile(file) {
  const formData = new FormData()
  formData.append('filename', file)
  return formData
}
